using System.IO;
using Common.Core.Configuration;
using Common.Core.Serialization;
using Common.Core.Testing.Objects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Testing.Core;

namespace Common.Core.Testing
{
	[TestClass]
	public class FileConfigurationContainerTests
	{
		[TestMethod, Owner( TestOwners.MichaelD_Bang ), DeploymentItem( "Common.Core.Testing/Resources/FileConfiguration.xaml" )]
		public void EnsureXamlObjectSerializesCorrectly()
		{
			var helper = new XamlSerializationHelper();
			var container = helper.Create<ConfigurationContainer>( "FileConfiguration.xaml" );
			var item = container.Get<CommonObject>( "CommonKey" );
			Assert.IsNotNull( item );
			
			var expected = "Common Name";
			Assert.AreEqual( expected, item.Name );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang ), DeploymentItem( "Common.Core.Testing/Resources/FileConfiguration.xaml" )]
		public void EnsureXamlStringObjectSerializesCorrectly()
		{
			var xaml = File.ReadAllText( "FileConfiguration.xaml" );
			var helper = new XamlSerializationHelper();
			var container = helper.CreateFromXaml<ConfigurationContainer>( xaml );
			var item = container.Get<CommonObject>( "CommonKey" );
			Assert.IsNotNull( item );
			
			var expected = "Common Name";
			Assert.AreEqual( expected, item.Name );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void EnsureResourceXamlObjectSerializesCorrectly()
		{
			var helper = new XamlSerializationHelper();
			var container = helper.Create<ConfigurationContainer>( GetType().Assembly, "Common.Core.Testing.Resources.ResourceConfiguration.xaml" );
			var item = container.Get<CommonObject>( "CommonKey" );
			Assert.IsNotNull( item );
			
			var expected = "Common Name";
			Assert.AreEqual( expected, item.Name );
		}
	}

	/// <summary>
	/// Summary description for ConfigurationContainerTests
	/// </summary>
	[TestClass]
	public class ConfigurationContainerTests
	{
		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void EnsureXamlObjectSerializesCorrectly()
		{
			var container = new Configuration();
			var item = container.Get<CommonObject>( "CommonKey" );
			Assert.IsNotNull( item );
			
			var expected = "Common Name";
			Assert.AreEqual( expected, item.Name );
		}

		[TestMethod, Owner( TestOwners.MichaelD_Bang )]
		public void EnsureXamlDefaultObjectSerializesCorrectly()
		{
			var container = new Configuration();
			var item = container.Get<CommonObject>();
			Assert.IsNotNull( item );
		}

	}
}